Skip to content

MAINT replace deprecated scipy distance_matrix with cdist#1188

Open
chaoz23 wants to merge 1 commit into
scikit-learn-contrib:masterfrom
chaoz23:fix/smoten-scipy-cdist
Open

MAINT replace deprecated scipy distance_matrix with cdist#1188
chaoz23 wants to merge 1 commit into
scikit-learn-contrib:masterfrom
chaoz23:fix/smoten-scipy-cdist

Conversation

@chaoz23

@chaoz23 chaoz23 commented Jul 18, 2026

Copy link
Copy Markdown

What

SciPy 1.18 deprecates scipy.spatial.distance_matrix in favour of scipy.spatial.distance.cdist (scheduled for removal in SciPy 1.20). ValueDifferenceMetric.pairwise still calls it, so under SciPy ≥ 1.18 it emits a DeprecationWarning — which currently fails the SMOTEN test suite (warnings are treated as errors).

Change

Switch the call to cdist(..., metric="minkowski", p=self.k), which computes the identical Minkowski-p distance matrix.

Verification

  • Numerical equivalence checked directly: distance_matrix vs cdist(metric="minkowski") match exactly (max abs diff 0.0) for p = 1, 2, 3.
  • imblearn/metrics/tests/test_pairwise.py — 132 passed (VDM results unchanged).
  • imblearn/over_sampling/_smote/tests/test_smoten.py — 5 passed (previously failing on the deprecation).
  • ruff and black clean.

No behavioural change; distances are identical.

@chaoz23
chaoz23 force-pushed the fix/smoten-scipy-cdist branch from 7aaa600 to 2d21704 Compare July 18, 2026 07:15
scipy 1.18 deprecates scipy.spatial.distance_matrix in favor of
scipy.spatial.distance.cdist (removal scheduled for scipy 1.20), which
currently raises a DeprecationWarning (and fails the SMOTEN tests that
treat warnings as errors). Switch ValueDifferenceMetric to cdist with the
Minkowski metric; the computed distances are identical.
@chaoz23
chaoz23 force-pushed the fix/smoten-scipy-cdist branch from 2d21704 to d7d5503 Compare July 18, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant